import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = (data, details, brandIdId, enterprise) => {
    const requiredFields = [];
    if(!brandIdId)
        requiredFields.push(
            formatMessage({
                id: 'validator.brandId',
                defaultMessage: '品牌'
            })
        );
    if(!enterprise.dealerId)
        requiredFields.push(
            formatMessage({
                id: 'validator.dealerId',
                defaultMessage: '总代'
            })
        );
    if(!data || !data.claimType)
        requiredFields.push(
            formatMessage({
                id: 'validator.claimType',
                defaultMessage: '索赔类型'
            })
        );
    if(!data || !data.claimPartType)
        requiredFields.push(
            formatMessage({
                id: 'validator.claimPartType',
                defaultMessage: '索赔配件类型'
            })
        );
    if(!data || !data.saleShipmentId)
        requiredFields.push(
            formatMessage({
                id: 'validator.saleShipmentId',
                defaultMessage: '发运单编号'
            })
        );
    if(!data || !data.batchNumber)
        requiredFields.push(
            formatMessage({
                id: 'validator.batchNumber',
                defaultMessage: '批次号'
            })
        );
    if(!data || !data.urgencyLevel)
        requiredFields.push(
            formatMessage({
                id: 'validator.urgencyLevel',
                defaultMessage: '紧急程度'
            })
        );
    if(!data || !data.requireCompensationWay)
        requiredFields.push(
            formatMessage({
                id: 'validator.requireCompensationWay',
                defaultMessage: '需求赔付方式'
            })
        );
    if(data.requireCompensationWay === 2 && !data.requireTransportType)
        requiredFields.push(
            formatMessage({
                id: 'validator.requireTransportType',
                defaultMessage: '需求运输方式'
            })
        );
    if(!data || !data.description)
        requiredFields.push(
            formatMessage({
                id: 'validator.description',
                defaultMessage: '索赔详细描述'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    if(!details || (details && details.length === 0)) {
        message.warning(formatMessage({
            id: 'validator.message.detailQuantity',
            defaultMessage: '清单不能为空！'
        }));
        return false;
    }
    if(details.some(d => !d.quantity)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.quantity',
            defaultMessage: '清单中索赔数量必填!'
        })}`);
        return false;
    }
    if(details.some(d => !d.productCategoryId)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.productCategoryId',
            defaultMessage: '清单中车型必填!'
        })}`);
        return false;
    }
    return true;
};

export const approveOrUpdateOrderValidator = (data, details) => {
    const requiredFields = [];
    if(!data || !data.status)
        requiredFields.push(
            formatMessage({
                id: 'validator.status',
                defaultMessage: '审核结果'
            })
        );
    if(!data || !data.actualCompensationWay)
        requiredFields.push(
            formatMessage({
                id: 'validator.actualCompensationWay',
                defaultMessage: '实际赔付方式'
            })
        );
    if(!data || !data.actualTransportType)
        requiredFields.push(
            formatMessage({
                id: 'validator.actualTransportType',
                defaultMessage: '实际运输方式'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    if(details.some(d => !d.dutyUnitId)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.dutyUnitId',
            defaultMessage: '清单中责任单位必填!'
        })}`);
        return false;
    }
    if(details.find(d => d.mfgIsClaim !== 1 && d.mfgIsClaim !== 0 && d.mfgIsClaim !== true && d.mfgIsClaim !== false)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.mfgIsClaim',
            defaultMessage: '清单中制造中心确认索赔必填!'
        })}`);
        return false;
    }
    return true;
};

export const reasonOrUpdateOrderValidator = details => {
    const requiredFields = [];
    if(details.find(d => d.planIsClaim !== 1 && d.planIsClaim !== 0 && d.planIsClaim !== true && d.planIsClaim !== false)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.planIsClaim',
            defaultMessage: '清单中计划部确认索赔必填!'
        })}`);
        return false;
    }
    return true;
};

export const upgradeOrUpdateOrderValidator = details => {
    const requiredFields = [];
    if(details.find(d => d.qualityIsClaim !== 1 && d.qualityIsClaim !== 0 && d.qualityIsClaim !== true && d.qualityIsClaim !== false)) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.qualityIsClaim',
            defaultMessage: '清单中质管中心确认索赔必填!'
        })}`);
        return false;
    }
    return true;
};

